<template>
    <div>
        <div class="register_content">
            <div class="register_project_name_one">{{ systemName }}</div>
            <el-card>
                <div class="register_content_title">租户注册</div>
                <div class="edit_page_div">
                    <el-form ref="form" :model="form" :rules="rules" :show-message="false" label-width="100px" style="float: left;">
                        <el-form-item label="租户编号" prop="tenantCode">
                            <el-input v-model="form.tenantCode" style="width: 400px;"></el-input>
                        </el-form-item>
                        <el-form-item label="租户名称" prop="tenantName">
                            <el-input v-model="form.tenantName" style="width: 400px;"></el-input>
                        </el-form-item>
                        <el-form-item label="租户账号" prop="accountNumber">
                            <el-input v-model="form.accountNumber" style="width: 400px;"></el-input>
                        </el-form-item>
                        <el-form-item label="租户密码" prop="password">
                            <el-input v-model="form.password" style="width: 400px;"></el-input>
                        </el-form-item>
                    </el-form>
                </div>
                <div class="register_button">
                    <el-button class="button_register" v-loading.fullscreen.lock="loading" type="primary" @click="submit">注 册</el-button>
                    <el-button class="button_login" type="primary" @click="onLogin">登 录</el-button>
                </div>
            </el-card>
        </div>
    </div>
</template>

<script>
export default {
    name: "register",
    data() {
        return {
            loading: false,
            systemName: CONFIG.systemName,

            form: {
                tenantCode: '', //会员编号
                tenantName: '', //会员名称
                accountNumber: '', //金额
                password: '', //折扣
            },
            rules: {
                tenantCode: [{required: true, message: '', trigger: 'change'}],
                tenantName: [{required: true, message: '', trigger: 'change'}],
                accountNumber: [{required: true, message: '', trigger: 'change'}],
                password: [{required: true, message: '', trigger: 'change'}],
            },
        }
    },
    methods: {
        submit() {
            this.$refs.form.validate((valid) => {
                if (valid) {
                    this.loading = true;
                    this.$axios.post("/CHILD_SYSTEM/systemTenant/" + (this.id ? "update" : "insert"), this.form).then(res => {
                        this.resetForm();
                        this.$message.success(res.message);
                    }).finally(() => {
                        this.loading = false;
                    })
                } else {
                    this.$message.error('表单填写有误');
                    return false;
                }
            });
        },
        onLogin() {
            this.$router.replace('/');
        },
    }
}
</script>

<style lang="scss">
.register_content {
    position: relative;
    width: 100%;
    height: calc(100vh);

    .register_project_name_one {
        width: 100%;
        height: 60px;
        line-height: 60px;
        font-size: 36px;
        text-align: center;
        position: absolute;
        top: 50%;
        margin-top: -300px;
    }

    .el-card {
        width: 560px;
        position: absolute;
        left: 50%;
        top: 40%;
        margin-left: -280px;
        margin-top: -140px;

        .register_content_title {
            height: 40px;
            line-height: 40px;
            font-size: 24px;
            text-align: center;
        }

        .register_button {
            margin: 20px;

            .button_register {
                width: 220px;
                float: left;
            }

            .button_login {
                width: 220px;
                float: right;
            }

        }
    }
}
</style>